package com.crazy.multids.config.common;

import lombok.extern.slf4j.Slf4j;

/**
 * 此类的描述是：
 *
 * @author crazyhu@wezhuiyi.com
 * @date 2018-09-16 15:22
 **/
@Slf4j
public class DataSourceContextHolder {

    private static final ThreadLocal<DataSourceEnum> local = new ThreadLocal<DataSourceEnum>();

    public static DataSourceEnum getDataSourceType() {
        return local.get();
    }

    /**
     * 读库
     */
    public static void setRead() {
        local.set(DataSourceEnum.READ);
        log.info("数据库切换到读库...");
    }

    /**
     * 写库
     */
    public static void setWrite() {
        local.set(DataSourceEnum.WRITE);
        log.info("数据库切换到写库...");
    }

    public static void clear(){
        local.remove();
    }
}
